﻿using CustomPixelShaderEffect.AttributeUsageFloder;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;
using Microsoft.UI.Xaml.Data;
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Navigation;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;

// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.

namespace CustomPixelShaderEffect
{
    /// <summary>
    /// An empty window that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class MainWindow : Window
    {
        public MainWindow()
        {
            this.InitializeComponent();
            Init();
        }

        void Init()
        {
            list.ItemsSource = GetPages(typeof(MainWindow));
            list.IsItemClickEnabled = true;
            list.SelectionChanged += (s, e) =>
            {
                if (list.SelectedItem is PageInfo info)
                {
                    myFrame.Navigate(info.Page);
                }
            };
        }

        IEnumerable<PageInfo> GetPages(Type tyep)
        {
            //获取指定的程序集
            var assembly = tyep.Assembly;
            //获取程序集下的所有类
            var typeInfos = assembly.GetTypes();
            foreach (TypeInfo typeInfo in typeInfos)
            {
                var pta = typeInfo.GetCustomAttribute<PageTypeAttribute>();
                if (pta != null)
                {
                    yield return new PageInfo(pta.Title, typeInfo);
                }
            }
        }

    }

    public class PageInfo
    {
        public string Title { get; set; }
        public Type Page { get; set; }
        public PageInfo(string title, Type page)
        {
            Title = title;
            Page = page;
        }
    }
}
